package example

import grails.testing.web.controllers.ControllerUnitTest
import org.grails.datastore.mapping.multitenancy.exceptions.TenantNotFoundException
import org.grails.datastore.mapping.multitenancy.resolvers.SystemPropertyTenantResolver
import spock.lang.Stepwise

@Stepwise
class VehicleControllerSpec extends HibernateFixedTenantContextSpec implements ControllerUnitTest<VehicleController> {

    void 'Test the index action returns the correct model'() {

        when: 'The index action is executed'
        controller.index()

        then: 'The model is correct'
        !model.vehicleList
        model.vehicleCount == 0
    }

    void 'Test the index action with no tenant id'() {
        when: 'there is no tenant id'
        System.setProperty(SystemPropertyTenantResolver.PROPERTY_NAME, '')
        controller.index()

        then:
        thrown(TenantNotFoundException)
    }

}
